<h1><%= title 'Account Settings' %></h1>

<div class="row">
  <div class="col-sm-8">
    <div class="panel panel-default">
      <div class="panel-heading">Emails</div>
      <div class="panel-body">
        <%= simple_form_for(current_user, url: account_path, html: { class: 'form-vertical' }) do |form| %>
          <%= form.input :email, label: false, input_html: {size: 40} %>
          <%= form.input :emails_enabled %>
          <%= form.submit 'Update Email Preferences', class: 'btn btn-primary' %>
        <% end %>
      </div>
    </div>

    <div class="panel panel-default">
      <div class="panel-heading">Accounts</div>
      <div class="panel-body">
        <%= link_to login_path(host_type: 'github', return_to: request.original_url), class: 'btn btn-primary' do %>
          <%= fa_icon('github') %> Connect GitHub
        <% end %>
        <%= link_to login_path(host_type: 'gitlab', return_to: request.original_url), class: 'btn btn-primary' do %>
          <%= fa_icon('gitlab') %> Connect GitLab
        <% end %>
        <%= link_to login_path(host_type: 'bitbucket', return_to: request.original_url), class: 'btn btn-primary' do %>
          <%= fa_icon('bitbucket') %> Connect Bitbucket
        <% end %>
        <h4>Connected Accounts</h4>
        <% current_user.viewable_identities.each do |identity| %>
          <button class="btn btn-default tip" title="<%= RepositoryHost::Base.format(identity.provider) %>">
            <%= fa_icon(identity.provider) %> <%= identity.nickname %>
          </button>
        <%end %>
      </div>
    </div>

    <div class="panel panel-default">
      <div class="panel-heading">API Key</div>
      <div class="panel-body">
        <p>
          Your private token is used to access application resources without authentication. <strong>Keep it secret!</strong>
        </p>
        <p>
          View API documentation here: <%= link_to 'libraries.io/api', api_path %>
        </p>
        <div class="well">
          <%= current_user.api_key %>
        </div>
        <p>
          <small>
            Rate limit: <strong><%= current_user.current_api_key.try(:rate_limit) || 0 %> requests per minute</strong>
          </small>
        </p>
      </div>
    </div>

    <div class="panel panel-default">
      <div class="panel-heading">Profile visibility</div>
      <div class="panel-body">
        <p>
          Hide your profile if you do not wish for your profile to be visible on the site or by search engines.
        </p>
        <%= simple_form_for(current_user, url: account_path, html: { class: 'form-vertical' }) do |form| %>
          <%= form.input :hidden, as: :boolean, label: 'Hide my profile' %>
          <%= form.submit 'Update visibility preferences', class: 'btn btn-primary' %>
        <% end %>
      </div>
    </div>

    <div class="panel panel-default">
      <div class="panel-heading">Account deletion</div>
      <div class="panel-body">
        <p>
          Delete your account and all related private data
        </p>
        <%= link_to 'Delete Account', delete_account_path, class: 'btn btn-danger' %>
      </div>
    </div>
  </div>
  <div class="col-sm-4">

  </div>
</div>
